package com.wh1200.mybatis.xmlless.model.component

import com.wh1200.kotlin.only
import com.wh1200.mybatis.xmlless.model.ConditionConnector

/**
 * @author 吴昊
 * @date 2024/01/12
 * @version 1.0
 * @since v4.0.0
 */
class ExpressionGroup : ConditionExpression() {

  val expressions: MutableList<ConditionExpression> = mutableListOf()
  var connector: ConditionConnector = ConditionConnector.AND

  override fun toString(): String {
    if (expressions.isEmpty()) {
      return ""
    }
    if (expressions.size > 1) {
      return "(" + expressions.joinToString(" $connector ") + ")"
    }
    return expressions.only().toString()
  }

  fun addExpression(stringExpression: ConditionExpression) {
    expressions.add(stringExpression)
  }

}
